// Preload Images
img1 = new Image(16, 16);  
img1.src="/resources/images/spinner.gif";

img2 = new Image(220, 19);  
img2.src="/resources/images/ajax-loader.gif";

// When DOM is ready
$(document).ready(function(){

// Launch MODAL BOX if the Login Link is clicked
$("#login_link").click(function(){
$('#login_form').modal();
});
$("#register_link").click(function(){
$('#register_form').modal();
});
// Ajax login
// When the form is submitted
$("#login_status > form").submit(function(){  

// Hide 'Submit' Button
$('#submit1').hide();

// Show Gif Spinning Rotator
$('#ajax_loading1').show();

// 'this' refers to the current submitted form  
var str = $(this).serialize();  

// -- Start AJAX Call --

$.ajax({  
    type: "GET",
    url: "/row/login",  // Send the login info to this page
    data: str,  
    success: function(msg){  
   
$("#login_status").ajaxComplete(function(){  
 
 // Show 'Submit' Button
$('#submit1').show();

// Hide Gif Spinning Rotator
$('#ajax_loading1').hide();  

 if(msg == 'OK') // LOGIN OK?
 {  
 var login_response = '<div id="logged_in">' +
	 '<div style="width: 350px; float: left; margin-left: -10px;">' + 
	 '<div style="width: 40px; float: left;">' +
	 '<img style="margin: 10px 0px 10px 0px;" align="absmiddle" src="/resources/images/ajax-loader.gif">' +
	 '</div>' +
	 '<div style="margin: 10px 0px 0px 10px; float: right; width: 300px;">'+ 
	 "Te has logueado satisfactoriamente! <br /> Espere mientras se redirige...</div></div>";

$('a.modalCloseImg').hide();  

$('#simplemodal-container').css("width","400px");
$('#simplemodal-container').css("height","100px");
 
 $(this).html(login_response); // Refers to 'status'

// After 3 seconds redirect the 
setTimeout('go_to_private_page()', 3000); 
 }  
 else // ERROR?
 {  
 login_response = "<div id='notification_error'>#{msg.logdenied}</div>";
 $('#login_response').html(login_response);
 }  
      
 });  
   
 }  
   
  });  
  
// -- End AJAX Call --

return false;

}); // end submit event


// Ajax register
// When the form is submitted
$("#register_status > form").submit(function(){  

// Hide 'Submit' Button
$('#submit2').hide();

// Show Gif Spinning Rotator
$('#ajax_loading2').show();

// 'this' refers to the current submitted form  
var str2 = $(this).serialize();  

// -- Start AJAX Call --

$.ajax({  
    type: "GET",
    url: "/row/register_user",  // Send the login info to this page
    data: str2, 
    success: function(msg2){  
   
$("#register_status").ajaxComplete(function(){  
 
 // Show 'Submit' Button
$('#submit2').show();

// Hide Gif Spinning Rotator
$('#ajax_loading2').hide();  

 if(msg2 == 'OK') // LOGIN OK?
 {  
 var register_response = '<div id="logged_in">' +
	 '<div style="width: 350px; float: left; margin-left: -10px;">' + 
	 '<div style="width: 40px; float: left;">' +
	 '<img style="margin: 10px 0px 10px 0px;" align="absmiddle" src="/resources/images/ajax-loader.gif">' +
	 '</div>' +
	 '<div style="margin: 10px 0px 0px 10px; float: right; width: 300px;">'+ 
	 "Te has registrado satisfactoriamente! <br /> Espere mientras se redirige...</div></div>";

$('a.modalCloseImg').hide();  

$('#simplemodal-container').css("width","400px");
$('#simplemodal-container').css("height","100px");
 
 $(this).html(register_response); // Refers to 'status'

// After 3 seconds redirect the 
 setTimeout('end_register()', 1000); 
 }  
 else // ERROR?
 {  
 register_response = msg2;
 $('#register_response').html(register_response);
 }  
      
 });  
   
 }  
   
  });  
  
// -- End AJAX Call --

return false;

}); // end submit event

});

function go_to_private_page()
{
window.location = '/row/index'; // Members Area
}
function end_register()
{
    $.modal.close();
    $('#login_form').modal();
}